﻿Imports BusinessRule.Business
Imports BusinessRule.BusinessFactory
Imports BusinessRule.Common
Imports BusinessRule.DTO

Partial Class ChangePWD
    Inherits System.Web.UI.Page
    Protected oBusiness As uMESLoginBusiness = uMESBusinessFactory.instance.GetuMESLoginObject

    Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click

        ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>window.opener=null;window.open('','_self');window.close();</script>")
    End Sub

    Protected Sub btnChangePWD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChangePWD.Click
        Try
        
            Dim employee As uMES_AjaxEmployeeDto = oBusiness.GetEmployeeByName(txtInputusername.Text)
            If employee.strPassword <> txtPWD.Text Then
                Me.lblMessage.Text = "密码不正确"
                Exit Sub
            End If
            If String.IsNullOrWhiteSpace(txtNewPWD.Text) Then
                Me.lblMessage.Text = "新密码不能为空"
                Exit Sub
            End If
            If txtNewPWD.Text <> txtConfirmPWD.Text Then
                Me.lblMessage.Text = "新密码和确认密码不一致"
                Exit Sub
            End If
            Dim count = oBusiness.UpdateUserPassword(txtInputusername.Text, txtNewPWD.Text)
            If count > 0 Then
                Me.lblMessage.Text = "密码修改成功"
            End If
        Catch ex As Exception
            Me.lblMessage.Text = ex.Message
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack Then

                Me.txtInputusername.Text = Request("user")
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class
